<template>
  <div class="my_heroes">
    <div class="head">
      <div class="tit">
        我的名将（{{ S_heroesList.length }}/{{ S_heroesAllList.length }}）
      </div>
      <div class="more" @click="showAll">
        <img src="../../../assets/kapai.svg" alt="" />
        <span>查看全部</span>
        <img class="r" src="../../../assets/right.svg" alt="" />
      </div>
    </div>
    <div class="list">
      <div class="wujiang">
        <vue-scroll :ops="ops">
          <div
            class="item"
            v-for="(item, index) in S_heroesList"
            :key="index"
            @click="heroeDetails(item)"
          >
            <div class="img">
              <img :type="item.quality" :src="item.avatar" />
            </div>
            <div class="name">{{ item.name }}</div>
          </div>
        </vue-scroll>
      </div>
      <div
        class="item append"
        :class="{ overflow: S_heroesList.length > 4 }"
        @click="eslist"
      >
        <div class="img">
          <img src="../../../assets/add.svg" alt="" />
        </div>
        <div class="name">招募武将</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "MyHeroes",
  data() {
    return {
      ops: {
        vuescroll: {
          mode: "slide",
        },
        scrollPanel: {
          scrollingX: true,
          scrollingY: false,
        },
        bar: {
          showDelay: 500,
          onlyShowBarOnScroll: true,
          keepShow: false,
          background: "rgba(0,0,0,0)",
          opacity: 1,
          hoverStyle: false,
          specifyBorderRadius: false,
          minSize: false,
          size: "5px",
          disable: false,
        },
      },
    };
  },
  computed: {
    ...mapState("data", ["userHeroes", "heroesList", "alldataLoading"]),
    S_heroesAllList() {
      let list = this.heroesList.filter((item) => item.quality === 4);
      return list;
    },
    S_heroesList() {
      let list = this.heroesList.filter(
        (item) => this.userHeroes.indexOf(item.id) !== -1 && item.quality === 4
      );
      return list;
    },
  },
  methods: {
    showAll() {
      this.checkLogin();
      this.$router.push("/myheroe");
    },
    eslist() {
      this.checkLogin();
      this.$router.push("/enlist");
    },
    heroeDetails(item) {
      console.log(item);
    },
  },
};
</script>

<style lang="scss" scoped>
.my_heroes {
  margin-top: 0.08rem;
  margin-bottom: 0.1rem;
  border-radius: 4px;
  border: 1px solid #ebebeb;
  .head {
    height: 0.32rem;
    background: #f5f5f5;
    border-radius: 5px 5px 0px 0px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.06rem 0 0.11rem;
    border-bottom: 1px solid #ebebeb;
    .tit {
      font-size: 0.12rem;
      color: #233d4d;
    }
    .more {
      display: flex;
      align-items: center;
      cursor: pointer;
      span {
        padding: 0 0.02rem 0 0.01rem;
        font-size: 0.12rem;
        color: #8c8c8c;
        white-space: nowrap;
      }
      img {
        height: 0.16rem;
        &.r {
          transform: translateY(0px);
        }
      }
    }
  }
  .list {
    margin: 0.12rem 0;
    white-space: nowrap;
    .wujiang {
      display: inline-block;
      max-width: calc(80%);
      .item {
        width: 0.48rem;
      }
    }
    .item {
      vertical-align: top;
      width: calc(20% - 0.17rem);
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      font-size: 0;
      margin: 0 0.079rem;
      position: relative;
      &.overflow {
        &:before {
          background: url(../../../assets/mask.png);
          background-size: 100% 100%;
        }
      }
      &.append {
        &:before {
          pointer-events: none;
          content: "";
          display: block;
          width: 0.48rem;
          height: 0.48rem;

          position: absolute;
          top: 0;
          left: -0.03rem;
          transform: translateX(-100%);
        }
        .img {
          width: calc(100% - 2px);
          padding-top: calc(100% - 2px);
          border: 1px solid #ebebeb;
          display: flex;
          justify-content: center;
          border-radius: 4px;
          img {
            left: 50%;
            margin-left: -0.08rem;
            width: 0.16rem;
          }
        }
        .name {
          color: #8c8c8c;
        }
      }
      &:first-child {
        margin-left: 0.11rem;
      }
      &:last-child {
        margin-right: 0;
      }
      .img {
        width: 100%;
        height: 0;
        padding-top: 100%;
        position: relative;

        img {
          width: 100%;
          height: 100%;
          border-radius: 3px;
          position: absolute;
          top: 0;
          left: 0;
          box-sizing: border-box;
          border-radius: 4px;
          &[type="4"] {
            border: 2px solid #f2ae32;
          }
          &[type="3"] {
            border: 2px solid #9363de;
          }
          &[type="2"] {
            border: 2px solid #7baefd;
          }
          &[type="1"] {
            border: 2px solid #99cfaa;
          }
        }
      }
      .name {
        margin-top: 0.08rem;
        text-align: center;
        white-space: nowrap;
        font-size: 0.12rem;
        line-height: 1em;
        color: #333333;
      }
    }
  }
}
</style>
